package com.yulan.BitOpt;

import org.junit.Test;

/**
 * 快速幂的demo
 * a^b  mod c 的快速运算
 */
public class QuickExponentiation {

    public long QuickExp(long a, long b, long c){
        long r = 1;
        long base = a;
        while(b!=0){
            if((b&1)==0){
                r = (r * base) % c;
            }

            base = (base * base ) % c;


            b >>= 1;
        }
        return r;
    }

    @Test
    public void test(){
        System.out.println(QuickExp(20,5,1000000007));
        System.out.println(QuickExp(10,20,1000000007));
    }
}
